<meta charset="utf-8">
<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">权限管理</a></li>
        <li class="active">用户管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="formSearch" class="form-horizontal form-search">
            <div class="form-group" style="padding:10px">
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="username">登录账号:</label>
                    <div class="col-xs-8">
                        <input type="text" class="form-control" id="username" placeholder="学号/教工号/管理员账号">
                    </div>
                </div>
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="nickname">用户姓名:</label>
                    <div class="col-xs-8">
                        <input type="text" class="form-control" id="nickname" placeholder="用户真实姓名">
                    </div>
                </div>
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="grade">年级:</label>
                    <div class="col-xs-8">
                        <select class="form-control" id="grade">
                            <option  value="">请选择</option>
                            <option th:each="grade:${grades}" th:value="${grade}" th:text="${grade}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group" style="padding:10px">
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="insId">所在学院:</label>
                    <div class="col-xs-8">
                        <select class="form-control" id="insId">
                            <option  value="">请选择</option>
                            <option th:each="institute:${institutes}" th:value="${institute.id}" th:text="${institute.instituteName}"></option>
                        </select>
                    </div>
                </div>
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="classId">所在班级:</label>
                    <div class="col-xs-8">
                        <select class="form-control" id="classId">
                            <option  value="">请选择</option>
                            <option th:each="class:${classes}" th:value="${class.id}" th:text="${class.className}"></option>
                        </select>
                    </div>
                </div>
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4">状态:</label>
                    <div class="col-xs-8">
                        <select id="status" class="form-control">
                            <option value="">请选择</option>
                            <option value="1">正常</option>
                            <option value="2">禁用</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group" style="padding:10px">
                <div class="col-md-12">
                	<label class="control-label col-xs-4"></label>
                	<div class="col-xs-8">
	                	<shiro:hasPermission name="user:list">
	                    	<button type="button" id="btn_query" class="btn btn-primary pull-right">查 询</button>
	                    </shiro:hasPermission>
	                	<button type="button" id="btn_requery" class="btn btn-primary pull-right" style="margin-right:5px">重 填</button>
                	</div>
                </div>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="btn-group">
            <shiro:hasPermission name="user:add">
            <button id="btn_add" type="button" class="btn btn-primary" data-toggle="modal" data-target="#userModal">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增
            </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="user:importUserExcel">
            <button id="btn_import_excel" type="button" class="btn btn-success" data-toggle="modal" data-target="#importExcelModal">
                <span class="glyphicon glyphicon-print" aria-hidden="true"></span> 批量导入用户
            </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="user:batchBan">
            <button id="btn_batch_ban" type="button" class="btn btn-warning">
                <span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span> 批量禁用
            </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="user:batchEnable">
            <button id="btn_batch_enable" type="button" class="btn btn-success">
                <span class="glyphicon glyphicon-retweet" aria-hidden="true"></span> 批量启用
            </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="user:batchAssignRole">
            <button type="button" onclick="batchAssignRoleList()" class="btn btn-info">
                <span class="glyphicon glyphicon-glass" aria-hidden="true"></span> 批量分配角色
            </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="user:batchDelete">
            <button id="btn_batch_delete" type="button" class="btn btn-danger">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 批量删除
            </button>
            </shiro:hasPermission>
        </div>
        <table id="table"></table>
    </div>
</section>
<!-- 用户新增模态框 -->
<div id="userModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog"  role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增用户</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="userForm">
                    <div class="box-body">
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">登录账号 <span style="color: red">*</span>:</label>
                            <div class="col-sm-8">
                                <input  name="username" class="form-control" min="3" require="必填项"  placeholder="学号/教工号/管理员账号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">真实姓名 <span style="color: red">*</span>:</label>
                            <div class="col-sm-8">
                                <input name="nickname" class="form-control"  min="3" require="必填项"  placeholder="学生姓名/教职工姓名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">年级<span style="color: red">*</span>:</label>
                            <div class="col-sm-8">
                                <input name="grade" class="form-control" require="必填项"  placeholder="入学年份">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">所在班级<span class="red">*</span>:</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="classId" id="classId" require="必填项">
		                            <option  value="">请选择</option>
		                            <option th:each="class:${classes}" th:value="${class.id}" th:text="${class.className}"></option>
                        		</select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">初始密码方式<span class="red">*</span>:</label>
                            <div class="col-sm-8 radio radioItem">
                            	<label>
                                    <input class="minimal"  type="radio"  name="passwordType" checked value="0"> 自定义密码
                                </label>
                                <label>
                                    <input class="minimal"  type="radio"  name="passwordType" value="1"> 默认123456
                                </label>
                            </div>
                    	</div>
                    	<div id="passwordGroup">
	                        <div class="form-group">
	                            <label  class="col-sm-3 control-label">登录密码 <span style="color: red">*</span>:</label>
	                            <div class="col-sm-8">
	                                <input name="password" type="password" class="form-control"  min="6" require="必填项"  placeholder="请输入密码包含大写、小写、特殊字符与数字">
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label  class="col-sm-3 control-label">确认密码 <span style="color: red">*</span>:</label>
	                            <div class="col-sm-8">
	                                <input name="confirmPassword" type="password" class="form-control"  min="6" require="必填项"  placeholder="">
	                            </div>
	                        </div>
	                    </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">性别 :</label>
                            <div class="col-sm-8">
                                <select name="sex" class="form-control">
                                    <option value="0">请选择</option>
                                    <option value="1">男</option>
                                    <option value="2">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">年龄 :</label>
                            <div class="col-sm-8">
                                <input name="age" class="form-control" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">邮箱 :</label>
                            <div class="col-sm-8">
                                <input name="email" class="form-control" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">电话 :</label>

                            <div class="col-sm-8">
                                <input name="phone" class="form-control" placeholder="">
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="pull-right">
                            <button type="button" id="saveUser" class="btn btn-info">确定</button>
                            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 用户详情模态框 -->
<div id="userDetailModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">用户信息</h4>
            </div>
            <div class="modal-body">
                <div id="userOpenWindow">
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 分配角色模态框 -->
<div id="assignRoleModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">分配角色</h4>
            </div>
            <div class="modal-body">
                <table id="assignRoleTable">
                </table>
            </div>
            <div class="modal-footer">
                <div class="pull-right">
                    <button type="button" id="saveAssign" class="btn btn-info">确定</button>
                    <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 分配角色模态框 -->
<div id="batchAssignRoleModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">分配角色</h4>
            </div>
            <div class="modal-body">
                <table id="batchAssignRoleTable">
                </table>
            </div>
            <div class="modal-footer">
                <div class="pull-right">
                    <button type="button" id="batchSaveAssign" class="btn btn-info">确定</button>
                    <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 导入Excel表模态框 -->
<div id="importExcelModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog"  role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">批量导入Excel表中用户</h4>
            </div>
            <div class="modal-body">
            	<form class="form-horizontal">
					<div class="box-body">
	    				<div class="form-group">
	                        <label class="col-sm-3 control-label">Excel表格路径 :</label>
	                        <div class="col-sm-8" style="position: relative">
	                            <input type="text" class="form-control" id="excelUrl" placeholder="excel路径（文件大小不得超过2M）">
	                            <div class="jax-upload-btn" style="position: absolute;right:20px;top: 0">
	                                <i class="fa fa-cloud-upload upload-file-btn"></i>
	                            </div>
	                       	</div>
	                   	</div>
	                   	<div id="upload-content" class="upload-content form-group" style="padding-left:0">
	                   		<label class="col-sm-3 control-label"></label>
	                   	</div>
	          		</div>
	          		<div class="box-footer">
	              		<div class="pull-right">
			                  <button type="button" id="saveExcel" class="btn btn-success">确定</button>
			                  <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
	              		</div>
	          		</div>
	          	</form>
            </div>
        </div>
    </div>
</div>
<script>
    var editFlag = "[[${@perms.hasPerm('user:edit')}]]";
    var assignRoleFlag="[[${@perms.hasPerm('user:assignRole')}]]";
    var banFlag = "[[${@perms.hasPerm('user:ban')}]]";
    var enableFlag = "[[${@perms.hasPerm('user:enable')}]]";
    var deleteFlag = "[[${@perms.hasPerm('user:delete')}]]";
    var userIdStr;//批量用户id
    var roleIdStr;//分配的角色
    var selectRoleIds;
    var userIdChecked;
    var loadRoleCount=0;
    var columns = [
        {checkbox: true },
        {
            field: 'username',
            title: '学号/教工号/管理',
            align : "center"
        },{
            field: 'nickname',
            title: '真实姓名',
            align : "center"
        },{
            field: 'institute',
            title: '所在学院',
            align : "center",
            formatter: function (value) {
                return value.instituteName;
            }
        },{
            field: 'classes',
            title: '所在班级',
            align : "center",
            formatter: function (value) {
                return value.className;
            }
        }
        ,{
            field: 'grade',
            title: '年级',
            align : "center",
        },{
            field: 'roles',
            title: '角色',
            align : "center",
            formatter:function(value,row, index){
                var roles="";
                $.each(value,function (i,item) {
                    roles+=item.name+",";
                })
                if (roles!=""){
                    roles = roles.substr(0, roles.length - 1);
                }
                return roles;
            }
        },
        {
            field: 'status',
            title: '用户状态',
            align : "center",
            formatter:function(value,row,index){
            	if(row.status==1){
            		return '<span class="label label-success">正常</span>';
            	}else if(row.status==0){
            		return '<span class="label label-danger">禁用</span>';
            	}
            }
        },
        {
            field : 'operation',
            title : '操作',
            align : "center",
            formatter : function(value,row,index) {
                var edit = editFlag=="true" ? '<button type="button" class="btn btn-primary btn-sm" onclick="editUser('+row.userId+')"><span class="glyphicon glyphicon-edit"></span> 编辑</button>' : '';
                var assign = assignRoleFlag=="true" ? '<button type="tutton" class="btn btn-info btn-sm" onclick="assignRoleList('+row.userId+')"><span class="glyphicon glyphicon-glass"></span> 分配角色</button>' : '';
                var ban = banFlag=="true"&&row.status==1 ? '<tutton type="button" class="btn btn-warning btn-sm" onclick="banUser('+row.userId+')"><span class="glyphicon glyphicon-ban-circle"></span> 禁用</button>' : '';
                var enable = enableFlag=="true"&&row.status==0 ? '<tutton type="button" class="btn btn-success btn-sm" onclick="enableUser('+row.userId+')"><span class="glyphicon glyphicon-retweet"></span> 启用</button>' : '';
                var del = deleteFlag=="true" ? '<button type="tutton" class="btn btn-danger btn-sm" onclick="deleteUser('+row.userId+')"><span class="glyphicon glyphicon-trash"></span> 删除</button>' : '';
                return edit + " " + del + " " + assign + " " + enable + " " + ban;
            }
        }];
    var options={
        id:"#table",
        url: '/user/list',
        columns:columns,
        toolbar: '#toolbar',
        showRefresh: true,
        queryParams : queryParams
    }
    Core.initTable(options);
    /*查询用户参数*/
    function queryParams(params) {
        var temp = { //这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
            limit : params.limit, //页面大小
            offset : params.offset, //页码
            username : $("#username").val(),
            nickname : $("#nickname").val(),
            grade : $("#grade").val(),
            insId : $("#insId").val(),
            classId: $("#classId").val(),
            status: $("#status").val(),
        };
        return temp;
    }

    /*查询角色参数*/
    function queryRoleParams(params){
        var temp = {
            userId :userIdChecked
        };
        return temp;
    }
    
    /*编辑*/
    function editUser(userId) {
        Core.load("#userOpenWindow","/user/edit?userId="+userId,function(){
            $("#userDetailModal").modal("show");
        },2);
    }
    
    $('.radioItem input').on('ifChecked',function(event){
		if(event.type == 'ifChecked'){
			var i = $('input:radio[name="passwordType"]:checked').val();
			if(i == 1){
				document.getElementById("passwordGroup").style.display="none";//隐藏	
			}else{
				document.getElementById("passwordGroup").style.display="";//显示
				}
			}
        }).iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue',
    });
    
    /*禁用*/
    function banUser(userId) {
        Core.confirm("确定禁用该用户？",function () {
            Core.postAjax("/user/ban",{"userId":userId},function (data) {
                if(data.status==200){
                	layer.msg(data.msg);
                    Core.refreshTable("#table");
                }else{
                	layer.msg(data.msg);
                }
            })
        })
    }
    
    /*启用*/
    function enableUser(userId) {
        Core.confirm("确定启用该用户？",function () {
            Core.postAjax("/user/enable",{"userId":userId},function (data) {
                if(data.status==200){
                	layer.msg(data.msg);
                    Core.refreshTable("#table");
                }else{
                	layer.msg(data.msg);
                }
            })
        })
    }
    
   /* 删除 */
    function deleteUser(userId){
    	Core.confirm("确定删除该用户？", function(){
    		Core.postAjax("/user/delete",{"userId":userId},function(data){
    			if(data.status==200){
    				layer.msg(data.msg);
    				Core.refreshTable("#table");
    			}else{
    				layer.msg(data.msg);
    			}
    		})
    	})
    }
    /*分配角色-列表查询*/
    function assignRoleList(userId) {
    	var result = Core.selectSingleData("#table");
        userIdChecked=userId;
        $("#assignRoleModal").modal("show");
        if(loadRoleCount==0){
            var roleColumns=[
                {checkbox: true },
                {
                    field: 'roleId',
                    title: '角色ID',
                    align : "center"
                }, {
                    field: 'name',
                    title: '角色名称',
                    align : "center"
                }, {
                    field: 'description',
                    title: '角色描述',
                    align : "center"
                },
                {
                    field: 'status',
                    title: '角色状态',
                    align : "center",
                    formatter:function(value,row, index){
                        return row.status == '1' ? "有效" : "删除";
                    }
                }];
            var roleOptions={
                id:"#assignRoleTable",
                url: "/user/assign/role/list",
                columns:roleColumns,
                pagination : false,
                queryParams : queryRoleParams,
                onLoadSuccess: function(){  //加载成功时执行
                    loadRoleCount=1;
                    Core.checkTableBy("#assignRoleTable",{field:"roleId", values:selectRoleIds});
                },
                responseHandler : handleRoleData,
            }
            Core.initTable(roleOptions);
        }
        if(loadRoleCount==1){
            Core.refreshTable("#assignRoleTable");
        }
    }

    /*批量分配角色*/
    function batchAssignRoleList() {
    	var result = Core.selectSingleData("#table");
        userIdChecked="1";
        $("#batchAssignRoleModal").modal("show");
        if(loadRoleCount==0){
            var roleColumns=[
                {checkbox: true },
                {
                    field: 'roleId',
                    title: '角色ID',
                    align : "center"
                }, {
                    field: 'name',
                    title: '角色名称',
                    align : "center"
                }, {
                    field: 'description',
                    title: '角色描述',
                    align : "center"
                },
                {
                    field: 'status',
                    title: '角色状态',
                    align : "center",
                    formatter:function(value,row, index){
                        return row.status == '1' ? "有效" : "删除";
                    }
                }];
            var roleOptions={
                id:"#batchAssignRoleTable",
                url: "/user/batch/assign/role/list",
                columns:roleColumns,
                pagination : false,
                queryParams : queryRoleParams,
                onLoadSuccess: function(){  //加载成功时执行
                    loadRoleCount=1;
                    Core.checkTableBy("#batchAssignRoleTable",{field:"roleId", values:selectRoleIds});
                },
                responseHandler : handleRoleData,
            }
            Core.initTable(roleOptions);
        }
        if(loadRoleCount==1){
            Core.refreshTable("#batchAssignRoleTable");
        }
    }
    
    /*处理角色数据*/
    function handleRoleData(res){
        selectRoleIds = res.hasRoles;
        return res.rows;
    }



    $(function () {
        /*查询*/
        $("#btn_query").click(function(){
            Core.refreshTable("#table");
        });
        /* 重置表单 */
        $("#btn_requery").click(function(){
        	$("#formSearch")[0].reset();
        });
        /*新增*/
        $("#btn_add").click(function(){
            Core.clearError("#userForm");
        });
        /*导入excel*/
        $("#btn_import_excel").click(function(){
            Core.clearError("#importExcelModal");
        });
        /*刷新用户列表 */
        $("#saveExcel").click(function(){
        	if($("#excelUrl").val() != ""){
        		$("#importExcelModal").modal("hide");
                Core.refreshTable("#table");
        	}else{
        		layer.msg("请上传数据");
        	}
        	
        })
        /*批量禁用*/
        $("#btn_batch_ban").click(function(){
            var checkedRows= Core.selectMutiData("#table");
            if(checkedRows){
                Core.confirm("确定禁用选中的"+checkedRows.length+"条记录？",function () {
                    userIdStr = "";
                    $.each(checkedRows, function (i, item) {
                        userIdStr += (item.userId + ",");
                    })
                    userIdStr = userIdStr.substring(0, userIdStr.length - 1);
                    Core.postAjax("/user/batch/ban", {"userIdStr": userIdStr}, function (data) {
                    	if (data.status == 200) {
                        	layer.msg(data.msg);
                            Core.refreshTable("#table");
                        }else{
                        	layer.msg(data.msg);
                        }
                    })
                })
            }
        });
        /*批量启用*/
        $("#btn_batch_enable").click(function(){
            var checkedRows= Core.selectMutiData("#table");
            if(checkedRows){
                Core.confirm("确定启用选中的"+checkedRows.length+"条记录？",function () {
                    userIdStr = "";
                    $.each(checkedRows, function (i, item) {
                        userIdStr += (item.userId + ",");
                    })
                    userIdStr = userIdStr.substring(0, userIdStr.length - 1);
                    Core.postAjax("/user/batch/enable", {"userIdStr": userIdStr}, function (data) {
                    	if (data.status == 200) {
                        	layer.msg(data.msg);
                            Core.refreshTable("#table");
                        }else{
                        	layer.msg(data.msg);
                        }
                    })
                })
            }
        });
        /*批量删除*/
        $("#btn_batch_delete").click(function(){
            var checkedRows= Core.selectMutiData("#table");
            if(checkedRows){
                Core.confirm("确定删除选中的"+checkedRows.length+"条记录？",function () {
                	userIdStr = "";
                    $.each(checkedRows, function (i, item) {
                        userIdStr += (item.userId + ",");
                    })
                    userIdStr = userIdStr.substring(0, userIdStr.length - 1);
                    Core.postAjax("/user/batch/delete", {"userIdStr": userIdStr}, function (data) {
                        if (data.status == 200) {
                        	layer.msg(data.msg);
                            Core.refreshTable("#table");
                        }else{
                        	layer.msg(data.msg);
                        }
                    })
                })
            }
        });
        
        /*批量分配角色保存*/
        $("#batchSaveAssign").click(function () {
            var checkedRows= Core.selectMutiData("#batchAssignRoleTable");
            var result= Core.selectMutiData("#table");
            if(checkedRows && result){
                Core.mask("#batchSaveAssign");
                Core.confirm("确定批量分配角色选中的"+result.length+"条记录？",function () {
	                userIdStr="";
	                $.each(result, function(i, item){
	                	userIdStr+=(item.userId+",");
	                })
	                userIdStr=userIdStr.substring(0,userIdStr.length-1);
	                roleIdStr="";
	                $.each(checkedRows, function (i, item) {
	                    roleIdStr+=(item.roleId+",");
	                })
	                roleIdStr=roleIdStr.substring(0,roleIdStr.length-1);
	                Core.postAjax('/user/batch/assign/role',{userIdStr:userIdStr,roleIdStr:roleIdStr},function (data) {
	                    Core.unmask("#batchSaveAssign");
	                    if(data.status==200){
	                        $("#batchAssignRoleModal").modal("hide");
	                        Core.refreshTable("#table");
	                    }
	                    layer.msg(data.msg);
	                })
                });
            }
        })
        
        /*保存用戶*/
        $("#saveUser").click(function(){
            if(doValidForm(userForm)){
                Core.mask("#saveUser");
                Core.postAjax("/user/add",$("#userForm").serialize(),function (data) {
                    Core.unmask("#saveUser");
                    if(data.status==200){
                        $("#userModal").modal("hide");
                        $("#userForm")[0].reset();
                        Core.refreshTable("#table")
                    }
                    layer.msg(data.msg);
                })
            };
        });
        
        /*分配角色保存*/
        $("#saveAssign").click(function () {
            var checkedRows= Core.selectMutiData("#assignRoleTable");
            if(checkedRows){
                Core.mask("#saveAssign");
                roleIdStr="";
                $.each(checkedRows, function (i, item) {
                    roleIdStr+=(item.roleId+",");
                })
                roleIdStr=roleIdStr.substring(0,roleIdStr.length-1);
                Core.postAjax('/user/assign/role',{userId:userIdChecked,roleIdStr:roleIdStr},function (data) {
                    Core.unmask("#saveAssign");
                    if(data.status==200){
                        $("#assignRoleModal").modal("hide");
                        Core.refreshTable("#table");
                    }
                    layer.msg(data.msg);
                })
            }
        })
    });
    
    $(function () {
        /*导入excel中数据*/
        $(".upload-file-btn").click(function(){
            if($("#upload-content").find(".upload-file-div").size()==0){
                var imgHtml = '<div class="col-md-8 upload-div upload-file-div">'+
                        '<div class="upload-item">'+
                        '<p class="upload-file"><i class="fa fa-folder-open fz-70"></i></p>'+
                        '<p class="upload-btns">'+
                        '<a type="button" class="btn btn-sm btn-block btn-success excelUploader">请选择Excel表格</a>'+
                        '</p>'+
                        '</div>'+
                        '</div>'
                $("#upload-content").append(imgHtml);
                $(".excelUploader").upload({
                    server : '[[@{/upload/importUserExcel}]]',
                    swf: '/img/Uploader.swf',
                    imgAccept:'xls,xlsx'
                }, function(url,msg,picker) {
                    $("#excelUrl").val(url);
                    layer.msg("导入成功");
                    echoGtUploadResMethd(url,picker);
                });
            }
        })
    })

</script>